package myJs.myPkg

import myJs.Implicits.JDJAn
import slinky.core._
import slinky.core.annotations.react

import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
import scala.scalajs.js.|
import org.scalajs.dom.History
import slinky.core.facade.ReactElement
import slinky.readwrite.ObjectOrWritten
import slinky.web.html.a

/**
 * Created by yz on 7/2/2022
 */

@js.native
trait Path extends js.Object {

  val key: String = js.native

  val pathname: String = js.native

}

case class NavigateOptions(state:JDJAn)

@js.native
trait Navigate extends js.Object{

  def apply(to:String):Unit=js.native

  def apply(to:String,options:ObjectOrWritten[NavigateOptions]):Unit=js.native

}

@JSImport("react-router-dom", JSImport.Default)
@js.native
object ReactRouterDOM extends js.Object {

  val Link: js.Object = js.native

  val Route: js.Object = js.native

  val BrowserRouter: js.Object = js.native

  val Routes: js.Object = js.native

  val HashRouter: js.Object = js.native

  val Switch: js.Object = js.native

  val Outlet: js.Object = js.native

  def useLocation(): Location = js.native

  def useResolvedPath(): Path = js.native

  def useNavigate(): Navigate = js.native

}

@js.native
trait Location extends js.Object {

  val key: String = js.native

  val pathname: String = js.native

  val search: String = js.native

  val state: JDJAn = js.native

}

@react object Link extends ExternalComponentWithAttributes[a.tag.type] {

  case class Props(to: String)

  override val component = ReactRouterDOM.Link

}

@react object Route extends ExternalComponent {

  case class Props(key: js.UndefOr[String] = js.undefined, path: String, element: ReactElement
                  )

  override val component = ReactRouterDOM.Route

}

object BrowserRouter extends ExternalComponentNoProps {

  override val component = ReactRouterDOM.BrowserRouter

}

object Routes extends ExternalComponentNoProps {

  override val component = ReactRouterDOM.Routes

}

@react object HashRouter extends ExternalComponent {

  case class Props(basename: js.UndefOr[String] = js.undefined)

  override val component = ReactRouterDOM.HashRouter

}

object Switch extends ExternalComponentNoProps {

  override val component = ReactRouterDOM.Switch

}

@react object Outlet extends ExternalComponent {

  case class Props()

  override val component = ReactRouterDOM.Outlet

}
